package com.eav.app.bluetoothsample

import android.bluetooth.BluetoothDevice
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView

/**
 *
 * @Description: 类作用描述
 * @Author: Arvin
 * @CreateDate: 2020/10/26 0026 下午 3:16
 * @Version: 1.0
 */
class BTAdapter(val context: Context, val list:ArrayList<BluetoothDevice>):BaseAdapter(){

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        var view =  LayoutInflater.from(context).inflate(R.layout.item_bluetooth, null)
        view.findViewById<TextView>(R.id.tvName).text = String.format(context.getString(R.string.bt_name), list[position].name)
        view.findViewById<TextView>(R.id.tvAddr).text = String.format(context.getString(R.string.bt_addr), list[position].address)
        return view
    }

    override fun getItem(position: Int): Any {
        return list[position]
    }

    override fun getItemId(position: Int): Long {
       return position.toLong()
    }

    override fun getCount(): Int {
        return list.size
    }
}